#include "FKLiveButtonReferent.h"

#include "FKLogger.h"

FKLiveButtonReferent::FKLiveButtonReferent(QString modelName, qint32 sourceId, QObject *parent):FKDisplayReferent(modelName,sourceId,parent),
    _lastCheck(QTime::currentTime()),_bDirection(1),_bOffset(0),_moreScale(0){
    FK_CBEGIN
//    setColor(QColor(Qt::gray));
//    move(0,0,-1);
    FK_CEND
}

FKLiveButtonReferent::~FKLiveButtonReferent(){
    FK_DBEGIN
    FK_DEND
}

void FKLiveButtonReferent::customAnimation(){
    QTime t(QTime::currentTime());
    float secElapsed=_lastCheck.msecsTo(t)/1000.0;
    _lastCheck=t;
    if(secElapsed>1.0)return;

    const float bmaxBound=0.02f;
    const float bminBound=-0.02f;
    const float bSpeed=0.05f;
    float bNewOffset=_bOffset+bSpeed*secElapsed*_bDirection;
    if(bNewOffset>=bmaxBound){
        bNewOffset=bmaxBound*2-bNewOffset;
        _bDirection=-1;
    }else if(bNewOffset<=bminBound){
        bNewOffset=bminBound*2-bNewOffset;
        _bDirection=1;
    }
    scale(QVector3D(0.0,bNewOffset-_bOffset,0.0));
    _bOffset=bNewOffset;

    const float scaleSpeed=1;
    if(_moreScale!=0){
        float scaling=(_moreScale>0 ? qMin(scaleSpeed*secElapsed,_moreScale) : qMax(-scaleSpeed*secElapsed,_moreScale));
        _moreScale-=scaling;
        scale(QVector3D(0,scaling,0));
    }
}

void FKLiveButtonReferent::enqueScale(float m){
    _moreScale+=m;
}
